﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PdfSharp;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf;
using PdfSharp.Drawing;


using common_park;

namespace PDFTest
{
    class PDFConvertImgModule
    {

        private string m_strSrcPath;
        private string m_strDstPath;

        public PDFConvertImgModule()
        {
            m_strSrcPath = string.Empty;
            m_strDstPath = string.Empty;
        }

        public bool ImageToPDF(string srcPath, string dstPath)
        {
            bool bRet = false;

            m_strSrcPath = srcPath;
            m_strDstPath = dstPath;

            string ext = FileUtils.GetExtName(m_strSrcPath);

            if(ext == ".jpg")
            {
                bRet = convJpgimage();
            }

            return bRet;
        }


        private bool convJpgimage()
        {
            PdfDocument aaa = new PdfDocument();
            
            PdfPage page = aaa.AddPage();

            XImage xImage = XImage.FromFile(m_strSrcPath);

            page.Width = xImage.PixelWidth;
            page.Height = xImage.PixelHeight;

            XGraphics gfx = XGraphics.FromPdfPage(page);

            gfx.DrawImage(xImage, 0, 0, xImage.PixelWidth, xImage.PixelHeight);

            aaa.Save(m_strDstPath);

            return true;
        }

    }
}
